Loading the required libraries ,

library(plyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following objects are masked from 'package:plyr':
## 
##     arrange, mutate, rename, summarise
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(DT)
library(tidyr)
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
setwd("C:/Users/Deepak kumar/Downloads/R/Hospital Ratings")

1 Loading data & cleaning

hos=read.csv("Hospital General Information.csv",stringsAsFactors = FALSE,header=TRUE)
glimpse(hos)
## Observations: 4,812
## Variables: 28
## $ Provider.ID                                                   <int> ...
## $ Hospital.Name                                                 <chr> ...
## $ Address                                                       <chr> ...
## $ City                                                          <chr> ...
## $ State                                                         <chr> ...
## $ ZIP.Code                                                      <int> ...
## $ County.Name                                                   <chr> ...
## $ Phone.Number                                                  <dbl> ...
## $ Hospital.Type                                                 <chr> ...
## $ Hospital.Ownership                                            <chr> ...
## $ Emergency.Services                                            <chr> ...
## $ Meets.criteria.for.meaningful.use.of.EHRs                     <chr> ...
## $ Hospital.overall.rating                                       <chr> ...
## $ Hospital.overall.rating.footnote                              <chr> ...
## $ Mortality.national.comparison                                 <chr> ...
## $ Mortality.national.comparison.footnote                        <chr> ...
## $ Safety.of.care.national.comparison                            <chr> ...
## $ Safety.of.care.national.comparison.footnote                   <chr> ...
## $ Readmission.national.comparison                               <chr> ...
## $ Readmission.national.comparison.footnote                      <chr> ...
## $ Patient.experience.national.comparison                        <chr> ...
## $ Patient.experience.national.comparison.footnote               <chr> ...
## $ Effectiveness.of.care.national.comparison                     <chr> ...
## $ Effectiveness.of.care.national.comparison.footnote            <chr> ...
## $ Timeliness.of.care.national.comparison                        <chr> ...
## $ Timeliness.of.care.national.comparison.footnote               <chr> ...
## $ Efficient.use.of.medical.imaging.national.comparison          <chr> ...
## $ Efficient.use.of.medical.imaging.national.comparison.footnote <chr> ...
dim(hos)
## [1] 4812   28
head(hos)
##   Provider.ID                    Hospital.Name                    Address
## 1       10001 SOUTHEAST ALABAMA MEDICAL CENTER     1108 ROSS CLARK CIRCLE
## 2       10005    MARSHALL MEDICAL CENTER SOUTH 2505 U S HIGHWAY 431 NORTH
## 3       10006   ELIZA COFFEE MEMORIAL HOSPITAL         205 MARENGO STREET
## 4       10007         MIZELL MEMORIAL HOSPITAL              702 N MAIN ST
## 5       10008      CRENSHAW COMMUNITY HOSPITAL        101 HOSPITAL CIRCLE
## 6       10011                ST VINCENT'S EAST 50 MEDICAL PARK EAST DRIVE
##         City State ZIP.Code County.Name Phone.Number        Hospital.Type
## 1     DOTHAN    AL    36301     HOUSTON   3347938701 Acute Care Hospitals
## 2       BOAZ    AL    35957    MARSHALL   2565938310 Acute Care Hospitals
## 3   FLORENCE    AL    35631  LAUDERDALE   2567688400 Acute Care Hospitals
## 4        OPP    AL    36467   COVINGTON   3344933541 Acute Care Hospitals
## 5    LUVERNE    AL    36049    CRENSHAW   3343353374 Acute Care Hospitals
## 6 BIRMINGHAM    AL    35235   JEFFERSON   2058383122 Acute Care Hospitals
##                            Hospital.Ownership Emergency.Services
## 1 Government - Hospital District or Authority                Yes
## 2 Government - Hospital District or Authority                Yes
## 3 Government - Hospital District or Authority                Yes
## 4              Voluntary non-profit - Private                Yes
## 5                                 Proprietary                Yes
## 6              Voluntary non-profit - Private                Yes
##   Meets.criteria.for.meaningful.use.of.EHRs Hospital.overall.rating
## 1                                         Y                       3
## 2                                         Y                       3
## 3                                         Y                       2
## 4                                         Y                       2
## 5                                         Y                       3
## 6                                         Y                       2
##   Hospital.overall.rating.footnote Mortality.national.comparison
## 1                                   Same as the national average
## 2                                     Below the national average
## 3                                     Below the national average
## 4                                   Same as the national average
## 5                                   Same as the national average
## 6                                   Same as the national average
##   Mortality.national.comparison.footnote
## 1                                       
## 2                                       
## 3                                       
## 4                                       
## 5                                       
## 6                                       
##   Safety.of.care.national.comparison
## 1         Above the national average
## 2       Same as the national average
## 3       Same as the national average
## 4                      Not Available
## 5                      Not Available
## 6         Below the national average
##           Safety.of.care.national.comparison.footnote
## 1                                                    
## 2                                                    
## 3                                                    
## 4 Results are not available for this reporting period
## 5 Results are not available for this reporting period
## 6                                                    
##   Readmission.national.comparison Readmission.national.comparison.footnote
## 1    Same as the national average                                         
## 2      Above the national average                                         
## 3    Same as the national average                                         
## 4      Below the national average                                         
## 5    Same as the national average                                         
## 6    Same as the national average                                         
##   Patient.experience.national.comparison
## 1             Below the national average
## 2           Same as the national average
## 3             Below the national average
## 4           Same as the national average
## 5                          Not Available
## 6             Below the national average
##       Patient.experience.national.comparison.footnote
## 1                                                    
## 2                                                    
## 3                                                    
## 4                                                    
## 5 Results are not available for this reporting period
## 6                                                    
##   Effectiveness.of.care.national.comparison
## 1              Same as the national average
## 2              Same as the national average
## 3              Same as the national average
## 4                Below the national average
## 5              Same as the national average
## 6                Below the national average
##   Effectiveness.of.care.national.comparison.footnote
## 1                                                   
## 2                                                   
## 3                                                   
## 4                                                   
## 5                                                   
## 6                                                   
##   Timeliness.of.care.national.comparison
## 1           Same as the national average
## 2             Above the national average
## 3             Above the national average
## 4             Above the national average
## 5             Above the national average
## 6           Same as the national average
##   Timeliness.of.care.national.comparison.footnote
## 1                                                
## 2                                                
## 3                                                
## 4                                                
## 5                                                
## 6                                                
##   Efficient.use.of.medical.imaging.national.comparison
## 1                         Same as the national average
## 2                           Below the national average
## 3                         Same as the national average
## 4                                        Not Available
## 5                                        Not Available
## 6                         Same as the national average
##   Efficient.use.of.medical.imaging.national.comparison.footnote
## 1                                                              
## 2                                                              
## 3                                                              
## 4           Results are not available for this reporting period
## 5           Results are not available for this reporting period
## 6
hos$Phone.Number=NULL
hos$Address=NULL
names(hos)[names(hos)=="County.Name"]="Country.Name"
length(unique(hos$Country.Name))
## [1] 1564
length(unique(hos$State))
## [1] 56

2 Hospital Analysis:

2.1 Hospital Types

temp=hos %>% select(Hospital.Name,Hospital.Type) %>% group_by(Hospital.Type)
temp=ddply(temp,.(Hospital.Type),summarise,count=n())
plot_ly(temp,x=~temp$Hospital.Type,y=~temp$count,color=temp$Hospital.Type,type="bar") %>% layout(title="Number of Hospitals by Type",xaxis=list(title="Type"),yaxis=list(title="Count"))

2.2 Hospital Ownership:

temp=hos %>% select(Hospital.Name,Hospital.Ownership) %>% group_by(Hospital.Ownership)
temp=ddply(temp,.(Hospital.Ownership),summarise,count=n())
plot_ly(temp,x=~temp$Hospital.Ownership,y=~temp$count,color=temp$Hospital.Ownership,type="bar") %>% layout(title="Number of Hospitals by Ownership",xaxis=list(title="Ownership"),yaxis=list(title="Count"),showlegend=FALSE)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

2.3 Hospital Type by Ownership:

Let us get to know how many hospitals in each type are owned by Gov/agency/NonProfit/Proprietary.

temp=as.data.frame(table(hos$Hospital.Type,hos$Hospital.Ownership))
temp=temp%>% group_by(Var2)
q=ggplot(temp,aes(Var2,Freq,fill=Var1))+geom_bar(stat="identity")+theme(axis.text.x =element_text(angle=90))+labs(x="Ownership",y="Count",fill="Hospital Type")+ggtitle("Count of Hospital in each Type and Ownership")
ggplotly(q)
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

Remarks:

  • Acute care hospitals are present in more numbers(3369) of which 1401 are owned by Private Voluntary Non profit.
  • 2052 hospitals are owned by Voluntary Non profit-Private hospitals across the country.
  • Voluntary Non-Profit tribals own 5 acute care and 4 critical access hospitals.
  • 1078 hospitals are owned by Government across the country of which 538 are Critical access hospitals.

2.4 Hospitals based on ratings:

temp=hos %>% filter(Hospital.overall.rating==5) %>% group_by(Hospital.Type,Hospital.Ownership) %>% summarise(total=n())
ggplot(temp,aes(Hospital.Type,total,fill=Hospital.Type))+geom_bar(stat="identity")+facet_wrap(~Hospital.Ownership)+theme(legend.position="None",axis.text.x = element_text(angle=90))+ggtitle("Hospital Type and Ownership distribution with Rating 5")

Observations:

  • There are no children Hospitals with rating 5.
  • There are 80 acute care hospitals with rating 5 as opposed to 2 Critical Access hospitals.
  • A majoring of Acute care hospitals are owned by Voluntary Non-Profit Private people.

3 Digging down further..

3.1 Total number of Hospitals in each State:

temp=ddply(hos,.(State),summarise,total=n()) %>% arrange(desc(total))
datatable(temp)
  • TX(Texas) has got highest hospitals in the whole country -411 nos followed by California (343),Florida(187).

3.2 Country wise hospital numbers in TX:

temp=hos %>% filter(hos$State=="TX")
length(unique(temp$Country.Name))
## [1] 183
temp=ddply(temp,.(Country.Name),summarise,total=n()) %>% arrange(desc(total))
datatable(temp)

3.3 Distribution of Hospital Type and Ownership in Texas:

temp=hos %>% filter(hos$State=="TX")
temp=ddply(temp,.(Hospital.Type,Hospital.Ownership),summarise,total=n()) %>% arrange(desc(total))
ggplot(temp,aes(Hospital.Type,total,fill=Hospital.Ownership))+geom_bar(stat="identity")+theme(axis.text.x = element_text(angle=90))+labs(x="Hospital Type",y="Total",fill="Ownership")+ggtitle("Distribution of Hospital Type and Ownership in Texas")

Observations:

  • Out of the total of 411 hospitals in TX ,there are 315 acute care hospitals in total of which 125 have proprietary ownership.48 Hospitals are owned by Government(Hospital District or Authority)
  • 85 of the acute care hospitals are owned by Voluntary Non-profit Private.
  • 137 Hospitals in TX are proprietary type.
  • There is only 14 Children hospitals in the whole TX of which none are owned by Government.Out of 14,a majority (11) are owned by Voluntary non-profit private.Lets us see in which all countries in TX are these children hospitals are present.
temp=hos %>% filter(State=="TX" & Hospital.Type=="Childrens")
datatable(temp)
temp %>% group_by(Country.Name,Hospital.Ownership,Emergency.Services) %>% summarise(count=n()) %>% ggplot(aes(Country.Name,count,fill=Hospital.Ownership))+geom_bar(stat="identity")+labs(x="Country Name",y="Count",fill="Ownership")+theme(axis.text.x = element_text(angle=90))+ggtitle("Children Hospital in TX")+facet_wrap(~Emergency.Services)

Observations:

  • Collin is the only country in TX that has children Hospital owned by Church.
  • Harris has 3 children hospital out of which 1 provides emergency services.
  • There are 9 hospitals providing emergency services in TX and 5 of them dont have this service.
  • Another interesting observation is that no data is available on the factors like rating,mortality,saftey of care,readmission national comparison,patient experience,effectiveness and timeliness of care and efficient use of medical imaging.Seems like a majority have not participated in IQR and OQR programs.